package ait.mediabroadcast.pauseresume;

import java.beans.PropertyChangeSupport;

import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpInputArgument;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.binding.annotations.UpnpService;
import org.teleal.cling.binding.annotations.UpnpServiceId;
import org.teleal.cling.binding.annotations.UpnpServiceType;
import org.teleal.cling.binding.annotations.UpnpStateVariable;

@UpnpService (
		serviceId=@UpnpServiceId("PauseResumeService"),
		serviceType=@UpnpServiceType(value="PauseResumeService", version=1)
)
public class PauseResumeService {
	
	private final PropertyChangeSupport propertyChangeSupport;

	public PauseResumeService() {
		propertyChangeSupport = new PropertyChangeSupport(this);
	}
	
	public PropertyChangeSupport getPropertyChangeSupport() {
		return propertyChangeSupport;
	}
	
	@UpnpStateVariable(defaultValue = "0", sendEvents=false)
	private String target = "false";
		
	@UpnpStateVariable(defaultValue = "0")
	private String status = "false";
	
	@UpnpStateVariable(defaultValue = "0")
	private String server = "false";
	
	@UpnpAction
	public void setTarget(@UpnpInputArgument(
			name = "newTargetValue") String newTargetValue) {
		String targetOldValue = target;
        target = newTargetValue;
        String statusOldValue = status;
        status = newTargetValue;

        // These have no effect on the UPnP monitoring but it's JavaBean compliant
        getPropertyChangeSupport().firePropertyChange("target", targetOldValue, target);
        getPropertyChangeSupport().firePropertyChange("status", statusOldValue, status);

        if (!newTargetValue.equals("false")) {
        	// This will send a UPnP event, it's the name of a state variable that sends events
        	getPropertyChangeSupport().firePropertyChange("Status", statusOldValue, status);
        }
	}
	
	@UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
	public String getTarget() {
		return target;
	}
	
	@UpnpAction(out = @UpnpOutputArgument(name = "RetStatusValue"))
	public String getStatus() {
		return status;
	}
	
	@UpnpAction
	public void setServer(@UpnpInputArgument(
			name = "newServer") String newServer) {
		String serverOldValue = server;
		server = newServer;

		// These have no effect on the UPnP monitoring but it's JavaBean compliant
        getPropertyChangeSupport().firePropertyChange("server", serverOldValue, server);
        
		if (!newServer.equals("false")) {
	        // This will send a UPnP event, it's the name of a state variable that sends events
	        getPropertyChangeSupport().firePropertyChange("Server", serverOldValue, server);
        }
	}
	
	@UpnpAction(out = @UpnpOutputArgument(name = "RetServerValue"))
	public String getServer() {
		return server;
	}
}
